package com.lyy.controller;

import lombok.SneakyThrows;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
 * @author Liangyaoyun
 */

@RestController
@RequestMapping("/api/v1/rabbitmq/direct")
public class DirectController {

    /** RabbitMQ推荐使用 `o.s.a.r.c.RabbitTemplate` 作为Java客户端 */
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @SneakyThrows
    @GetMapping("/send/{message}")
    public String send(@PathVariable String message) {
        // 发送消息
        rabbitTemplate.convertAndSend(
                "My_Exchange_Name",
                "My_Routing_Key",
                message);
        return "消息发送成功！";
    }
}